<?php

namespace App\Admin\Controllers;

use App\Models\TagTaxonomy;
use Encore\Admin\Http\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Table;
use Encore\Admin\Show;

class TagTaxonomyController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '标签分类';

    /**
     * Make a grid builder.
     *
     * @return Table
     */
    protected function table()
    {
        $table = new Table(new TagTaxonomy());

        $table->column('name', '名称');
        $table->column('icon', '图标');
        $table->column('display_order', '展示顺序');
        $table->column('created_at', __('Created at'));
        $table->column('updated_at', __('Updated at'));

        return $table;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(TagTaxonomy::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('icon', __('Icon'));
        $show->field('display_order', __('Display order'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('deleted_at', __('Deleted at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new TagTaxonomy());

        $form->text('name', '名称')->rules('required');
        $form->cloudinaryImage('icon', '图标');
        $form->number('display_order','展示顺序')->rules('integer');

        return $form;
    }
}
